package org.noote.libs.widget;

import javax.microedition.khronos.opengles.GL10;

import android.view.MotionEvent;

public class WidgetDekstop extends Widget_Window {

	protected WidgetRenderer _render;
	
	public WidgetDekstop(WidgetRenderer render) {
		super(null, null);
		_render = render;
	}
	
	public void loadTheme(GL10 gl)
	{
		_theme = new WidgetTheme();
		_theme.load(_render.getContext(), gl);
	}
	
	public WidgetTheme getTheme()
	{
		return _theme;
	}
	
	public Widget_Label createLabel()
	{
		Widget_Label label = new Widget_Label(this, _theme);
		label.create();
		return label;
	}
	
	public Widget_Pad createPad()
	{
		Widget_Pad pad = new Widget_Pad(this, _theme);
		pad.create();
		return pad;
	}

	public Widget_LabelPad createLabelPad()
	{
		Widget_LabelPad pad = new Widget_LabelPad(this, _theme);
		pad.create();
		return pad;
	}
	
	public Widget_DirectionPad createDirectionPad()
	{
		Widget_DirectionPad pad = new Widget_DirectionPad(this, _theme);
		pad.create();
		return pad;
	}
	
	public Widget_VRotationPad createVRotationPad()
	{
		Widget_VRotationPad pad = new Widget_VRotationPad(this, _theme);
		pad.create();
		return pad;
	}
	
	public Widget_ZoomPad createZoomPad()
	{
		Widget_ZoomPad pad = new Widget_ZoomPad(this, _theme);
		pad.create();
		return pad;
	}
	
	public Widget_Carousel createCarousel()
	{
		Widget_Carousel carousel = new Widget_Carousel(this, _theme);
		carousel.create();
		return carousel;
	}

	public void touch(final MotionEvent event, boolean bMultiTouch)
	{
		if(bMultiTouch)
		{
			for (int i = 0; i < event.getPointerCount(); i++) {
				if (event.getAction() == MotionEvent.ACTION_DOWN)
		        {   
					setTouchEvent((int)event.getX(i), _render.getHeight()-(int)event.getY(i), event.getPointerId(i), Widget_Window.TOUCH_PRESSED);
		        }
				else if (event.getAction() == MotionEvent.ACTION_MOVE)
		        {   
					setTouchEvent((int)event.getX(i), _render.getHeight()-(int)event.getY(i), event.getPointerId(i), Widget_Window.TOUCH_MOVED);
		        }
				else if (event.getAction() == MotionEvent.ACTION_UP)
		        {   
					setTouchEvent((int)event.getX(i), _render.getHeight()-(int)event.getY(i), event.getPointerId(i), Widget_Window.TOUCH_RELEASED);
		        }
			}
		}
		else
		{
			if (event.getAction() == MotionEvent.ACTION_DOWN)
			{
				setTouchEvent((int)event.getX(), _render.getHeight()-(int)event.getY(), 0, Widget_Window.TOUCH_PRESSED);
			}
			else if (event.getAction() == MotionEvent.ACTION_MOVE)
			{
				setTouchEvent((int)event.getX(), _render.getHeight()-(int)event.getY(), 0, Widget_Window.TOUCH_MOVED);
			}
			else if (event.getAction() == MotionEvent.ACTION_UP)
			{
				setTouchEvent((int)event.getX(), _render.getHeight()-(int)event.getY(), 0, Widget_Window.TOUCH_RELEASED);
			}
		}
	}
}
